package bb.lanxing.view

import android.content.Context
import android.util.AttributeSet
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.res.ResourcesCompat
import bb.lanxing.R
import bb.lanxing.util.DensityUtil

class WayPointIndicator @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
) : AppCompatTextView(context, attrs, defStyleAttr) {
    var number: Int = 0

    init {
        setTextSize(2, 12.0f)
        setTextColor(ResourcesCompat.getColor(context.resources, R.color.global_yellow_color, null))
        setBackgroundResource(R.drawable.ic_waypoint_start_small)
        layoutParams = ViewGroup.LayoutParams(DensityUtil.dp2px(32.0f), DensityUtil.dp2px(46.0f))
        gravity = 1
        setPadding(0, DensityUtil.dp2px(2.0f), 0, 0)
    }

    fun setSize(f: Float, f2: Float) {
        layoutParams = ViewGroup.LayoutParams(DensityUtil.dp2px(f), DensityUtil.dp2px(f2))
    }

    fun setUp(i: Int, z: Boolean, z2: Boolean, z3: Boolean) {
        if (z3) {
            setTextSize(2, 12.0f)
        } else {
            setTextSize(2, 18.0f)
        }
        setTextColor(ResourcesCompat.getColor(context.resources, R.color.global_yellow_color, null))
        if (i > 0) {
            text = i.toString()
            if (z) {
                if (z3) {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator_up_small)
                    return
                } else {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator_up)
                    return
                }
            } else if (z2) {
                if (z3) {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator_small)
                    return
                } else {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator)
                    return
                }
            } else {
                setTextColor(ResourcesCompat.getColor(context.resources, R.color.color_eb, null))
                if (z3) {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator_unenable_small)
                    return
                } else {
                    setBackgroundResource(R.drawable.ic_waypoint_indicator_unenable)
                    return
                }
            }
        }
        text = ""
        if (z) {
            if (z3) {
                setBackgroundResource(R.drawable.ic_waypoint_start_up_small)
            } else {
                setBackgroundResource(R.drawable.ic_waypoint_start_up)
            }
        } else if (z3) {
            setBackgroundResource(R.drawable.ic_waypoint_start_small)
        } else {
            setBackgroundResource(R.drawable.ic_waypoint_start)
        }
    }
    fun setEnd() {
        text = ""
        setBackgroundResource(R.drawable.ic_default)
    }
}